package com.superatom.concurrent.basic;

/**
 *  使用最简单的方式启动线程
 */
public class SimpleThread extends Thread {
    private int countDown = 5;
    private static int threadCount = 0;

    public SimpleThread(){
        // 入参就是Thread的名称
        super(Integer.toString(++threadCount));
        start();
    }

    // 用于打印this，调用toString()方法
    public String toString(){
        return "#" + getName() + "(" + countDown + "), ";
    }

    @Override
    public void run() {
        while (true){
            System.out.println(this);
            if (--countDown == 0){
                return;
            }
        }
    }

    public static void main(String[] args){
        for (int i = 0; i < 5; i++){
            new SimpleThread();
        }
    }
}
